﻿using UnityEngine;
using System;
using DG.Tweening;

namespace HareGame
{
    public partial class Util
    {
        public string Num2String(double num)
        {
            string unit = "";
            if (num >= 1000)
            {
                unit = "K";
                num /= 1000;
            }
            if (num >= 1000)
            {
                unit = "M";
                num /= 1000;
            }
            if (num >= 1000)
            {
                unit = "B";
                num /= 1000;
            }
            num = Math.Floor(num * 100) / 100; // 向下取整到小数点两位
            return num.ToString("0.##") + unit;
        }

        /// <summary>
        /// 时间格式
        /// </summary>
        /// <param name="second">秒</param>
        /// <returns></returns>
        public string Second2Times(int second)
        {
            return (second / 3600).ToString("##") + (second / 3600 > 0 ? "h" : "")
                + (second / 60 % 60).ToString("##") + (second / 60 % 60 > 0 ? "m" : "")
                + (second % 60).ToString("##") + (second % 60 > 0 ? "s" : "");
        }

        /// <summary>
        /// 时间格式
        /// </summary>
        /// <param name="second">秒</param>
        /// <returns></returns>
        public string Second2TimesFull(int second)
        {
            return (second / 3600).ToString("D2") + "h"
                + (second / 60 % 60).ToString("D2") + "m"
                + (second % 60).ToString("D2") + "s";
        }

        /// <summary>
        /// 时间转钻石
        /// </summary>
        /// <param name="second">秒</param>
        /// <returns></returns>
        public int Second2Diamond(int second)
        {
            return Mathf.CeilToInt(second / 60.0f);
        }
    }
}
